home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / ogrid100.zip / GLPARSER.INT < prev    next >
Text File  |  1994-12-29  |  3KB  |  96 lines

  1. {*****************************************************************************
  2.  
  3.   OOGrid Library(TM) v1.0 for Borland/Turbo Pascal (Real Mode/TV)
  4.   Copyright (C) 1994 by Arturo J. Monge
  5.   Portions Copyright (C) 1989,1990 Borland International, Inc.
  6.  
  7.   Borland's parser unit:
  8.     This is Borland's TCPARSER.PAS unit with some minor
  9.     modifications necessary for adapting TParserObject for
  10.     use by the TSpreadSheet object.
  11.  
  12.   Copyright (C) 1989,1990 Borland International, Inc.
  13.  
  14.   Last Modification : December 29th, 1994
  15.  
  16. *****************************************************************************}
  17.  
  18. {$O+,F+,N+,E+,X+}
  19.  
  20. unit GLParser;
  21.  
  22. {****************************************************************************}
  23.                                  interface
  24. {****************************************************************************}
  25.  
  26. uses Objects, GLCell, GLSupprt;
  27.  
  28. const
  29.   ParserStackSize = 10;
  30.   MaxFuncNameLen = 5;
  31.   TotalErrors = 7;
  32.   ExpLimit = 11356;
  33.   SqrLimit = 1E2466;
  34.   MaxExpLen = 4;
  35.   ErrParserStack = 1;
  36.   ErrBadRange = 2;
  37.   ErrExpression = 3;
  38.   ErrOperator = 4;
  39.   ErrOpenParen = 5;
  40.   ErrCell = 6;
  41.   ErrOpCloseParen = 7;
  42.  
  43. type
  44.   ErrorRange = 0..TotalErrors;
  45.  
  46.   TokenTypes = (Plus, Minus, Times, Divide, Expo, Colon, OParen, CParen,
  47.                 Num, CellT, Func, EOL, Bad, ERR);
  48.  
  49.   TokenRec = record
  50.     State : Byte;
  51.     case Byte of
  52.       0 : (Value : Extended);
  53.       1 : (CP : CellPos);
  54.       2 : (FuncName : String[MaxFuncNameLen]);
  55.   end;
  56.  
  57.   PParserObject = ^TParserObject;
  58.   TParserObject = object(TObject)
  59.        Inp : PString;
  60.        ParserHash : PCellHashTable;
  61.        PMaxCols : Word;
  62.        PMaxRows : Word;
  63.        Position : Word;
  64.        CurrToken : TokenRec;
  65.        StackTop : 0..ParserStackSize;
  66.        TokenError : ErrorRange;
  67.        ParseError : Boolean;
  68.        CType : CellTypes;
  69.        ParseValue : Extended;
  70.        Stack : array[1..ParserStackSize] of TokenRec;
  71.        TokenType : TokenTypes;
  72.        TokenLen : Word;
  73.        MathError, IsFormula : Boolean;
  74.     constructor Init(InitHash : PCellHashTable; InitInp : PString;
  75.                      InitPMaxCols, InitPMaxRows : Word);
  76.     function IsFunc(S : String) : Boolean;
  77.     procedure Push(Token : TokenRec);
  78.     procedure Pop(var Token : TokenRec);
  79.     function GotoState(Production : Word) : Word;
  80.     procedure Shift(State : Word);
  81.     procedure Reduce(Reduction : Word);
  82.     function NextToken : TokenTypes;
  83.     procedure Parse;
  84.     function CellValue(P : CellPos) : Extended;
  85.   end;
  86.  
  87. var
  88.    StandardParser : PParserObject;
  89.  
  90. {****************************************************************************}
  91.                                implementation
  92. {****************************************************************************}
  93.  
  94. ...
  95.  
  96. end. {...TSParser unit }